<template>
	<view class="content">
		<u-navbar leftIconColor="#fff" titleStyle="color:#fff" title="上传凭证" bgColor="transparent" :autoBack="true"
			:placeholder="false">
		</u-navbar>
		<view class="up_top">
			<view class="top_left">
				<view class="left-title">
					上传凭证
				</view>
				<view class="time">
					<view>请在</view>
					<u-count-down :time="30 * 60 * 60 * 1000" format="HH:mm:ss"></u-count-down>
					<view>前上传</view>
				</view>
			</view>
		</view>
		<view class="up_btn" v-if="isdown == 1" @click="isdown = 2">
			上传
		</view>
		<view class="up_btn" v-if="isdown == 2" @click="goupend(info.coin.id)">
			确认上传
		</view>
		<view class="my-content" v-if="info.coin">
			<view class="info-box">
				<view class="info-head">
					<image :src="info.order.u_img" mode=""></image>
					<view>
						{{info.order.user}}
					</view>
				</view>
				<view class="info-num">
					<view class="num-item">
						<view class="num">
							<text>{{info.coin.price}}</text>
						</view>
						<view class="num-text">
							单价(￥)
						</view>
					</view>
					<view class="num-item">
						<view class="num">
							<text>{{info.coin.num}}</text>
						</view>
						<view class="num-text">
							数量(KBT)
						</view>
					</view>
					<view class="num-item">
						<view class="num">
							<text>{{info.coin.total_price}}</text>
						</view>
						<view class="num-text">
							总价(￥)
						</view>
					</view>
				</view>
				<view class="order">
					<view>
						下单时间
					</view>
					<view class="order-time">
						{{$u.timeFormat(info.coin.start_time, 'yyyy-mm-dd hh:MM:ss')}}
					</view>
				</view>
				<view class="up-tips" v-if="this.status == 5">
					等待确认
				</view>
				<view class="up-tips" v-else>
					等待上传
				</view>
			</view>
			<view class="head" v-if="info.coin.pay_way.length > 0 && isdown == 1">
				<view :class="item.show == true?'activity':'stillness'" class="head-item"
					v-for="(item,index) in info.coin.pay_way" :key="index" @click="headTab(index)">
					<image v-if="item.status == 2" :src= "item.show==true?'/static/icon/icon2.png':'/static/icon/icon2-2.png'" mode="heightFix"></image>
					<image v-if="item.status == 1" :src="item.show==true?'/static/icon/icon1.png':'/static/icon/icon1-1.png'" mode="heightFix"></image>
					<image v-if="item.status == 4" :src="item.show==true?'/static/icon/icon3.png':'/static/icon/icon3-3.png'" mode="heightFix"></image>
					<view v-if="item.status == 2">
						微信
					</view>
					<view v-if="item.status == 1">
						支付宝
					</view>
					<view v-if="item.status == 4">
						USDT
					</view>
				</view>
			</view>
			<view v-if="isdown == 1&&info.coin.pay_way.length > 0">
				<view class="payment" v-if="status == index" v-for="(item,index) in info.coin.pay_way" :key="index">
					<view class="payment-item">
						<view class="payment-title" v-if="item.status == 2">
							微信名称
						</view>
						<view class="payment-title" v-if="item.status == 1">
							支付宝昵称
						</view>
						<view class="payment-title" v-if="item.status == 4">
							链名称
						</view>
						<view class="payment-right" v-if="item.status == 4">
							<view>
								TRC20
							</view>
						</view>
						<view class="payment-right" v-if="item.status == 2|| item.status == 1">
							<view>
								{{item.name}}
							</view>
							<view class="cory" @click="gocory(item.name)">复制</view>
						</view>
					</view>
					<view class="payment-item">
						<view class="payment-title" v-if="item.status == 2">
							微信号
						</view>
						<view class="payment-title" v-if="item.status == 1">
							支付宝账号
						</view>
						<view class="payment-title" v-if="item.status == 4">
							链名称
						</view>
						<view class="payment-right" v-if="item.status == 2|| item.status == 1|| item.status == 4">
							<view>
								{{item.account_num}}
							</view>
							<view class="cory" @click="gocory(item.account_num)">复制</view>
						</view>
					</view>
					<view class="payment-item" v-if="item.status == 2|| item.status == 1|| item.status == 4">
						<image class="code" :src="item.receive_qrcode" mode="widthFix"></image>
					</view>
				</view>
			</view>

			<view class="payment" v-if="isdown == 1" style="margin-top: 20rpx;">
				<view class="payment-item">
					<view class="payment-title">
						收款联系人
					</view>
					<view class="payment-right">
						<view>
							{{info.order.tel}}
						</view>
						<view class="cory" @click="gotel(info.order.tel)">
							拨打
						</view>
					</view>
				</view>
			</view>
			<view class="up-box" v-if="isdown == 2">
				<view class="code" @click="upload" v-if="receive_qrcode">
					<image :src="'https://web.sunsk.top'+receive_qrcode" mode="widthFix"
						style="width:100%;height:625rpx"/>
				</view>
				<view class="codeadd" @click="upload" v-else>
					<u-icon class="icon" name="plus" color="#ffffff" size="28"></u-icon>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 0,
				info: {},
				isdown: 1,
				receive_qrcode: ''
			}
		},
		onLoad(option) {
			this.getList(option.id)
		},
		methods: {
			goupend(id) {
				let app = this
				uni.showModal({
					title: '提示',
					content: '确定上传吗？',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							uni.showLoading({
								mask: true
							})
							let params = {
								id: id,
								voucher: app.receive_qrcode
							}
							app.$Request({
								method: 'POST',
								url: '/api/exchange/uploadVoucherykbPost',
								data: params
							}).then(res => {
								uni.hideLoading()
								if (res.code == 1) {
									uni.showToast({
										title: '上传成功',
										icon: 'none'
									})
									setTimeout(() => {
										uni.switchTab({
											url: '/pages/otc/index'
										})
									}, 1500)
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									})
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

			},
			upload() {
				let _self = this;
				//第一步:打开手机相册或者文件管理器选择文件
				uni.chooseImage({
					count: 1, //允许上传一张图片
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						//获得选择好的文件,就算只有一个文件也是数组
						const tempFilePaths = res.tempFilePaths;
						uni.showLoading()
						uni.uploadFile({
							url: '/api/upload/upload', //后端接口url
							filePath: tempFilePaths[0],
							header: {
								'Access-Control-Allow-Origin': '*',
							},
							data: {
								token: uni.getStorageSync("token") || ''
							},
							name: 'file', //和后端接口需要的参数名一致
							success: (res) => {
								_self.receive_qrcode = JSON.parse(res.data).url
								uni.showToast({
									title: "成功",
									icon: "none"
								})
							},
							complete: (ok) => {
								uni.hideLoading()
							}
						})
					}
				})
			},
			gocory(text) {
				uni.setClipboardData({
					data: text,
					showToast: false,
					success: function(res) {
						console.log(res)
						uni.showToast({
							title: '复制成功！',
							icon: 'none'
						})
					},
				})
			},
			gotel(tel) {
				uni.makePhoneCall({
					phoneNumber: tel, //电话号码
					success: function(e) {
						console.log(e);
					},
					fail: function(e) {
						console.log(e);

					}
				})
			},
			getList(id) {
				uni.showLoading();
				this.$Request({
					method: 'POST',
					url: '/api/exchange/uploadVoucherykb',
					data: {
						id
					}
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						this.info = res.data
						if (this.info.coin.pay_way.length > 0) {
							this.info.coin.pay_way.map(item => {
								item.show = false
							})
							this.info.coin.pay_way[0].show = true
						}
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			gonavto(url) {
				if (url == '') {
					uni.showToast({
						title: '开发中0.0',
						icon: 'none'
					})
				} else {
					uni.navigateTo({
						url: url
					})
				}
			},
			goincome() {
				uni.navigateTo({
					url: '/pages/my/income/index'
				})
			},
			headTab(index) {
				this.info.coin.pay_way.map((item) => {
					item.show = false
				})
				this.info.coin.pay_way[index].show = true
				this.status = index
				this.$forceUpdate();
			},
		}
	}
</script>

<style>
	page {
		background: #17191A;
	}
</style>
<style lang="scss" scoped>
	.content {
		width: 100%;
		background-image: url('../../../static/my/my-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 568rpx;
		padding-top: 120rpx;

		.up_top {
			width: 414rpx;
			height: 414rpx;
			margin: 0 auto;
			padding: 30rpx;
			background-image: url('../../../static/community/top-bg.png');
			background-repeat: no-repeat;
			background-size: 414rpx 414rpx;

			.top_left {
				padding-top: 33%;
				text-align: center;

				.left-title {
					font-size: 40rpx;
					font-weight: 600;
					color: #fff;
				}

				.time {
					font-size: 24rpx;
					color: #cbcbcb;
					margin-top: 20rpx;
					display: flex;
					align-items: center;
					justify-content: center;
				}
			}

			
		}
		.up_btn {
			text-align: center;
			font-size: 28rpx;
			font-weight: 600;
			line-height: 88rpx;
			width: 318rpx;
			height: 88rpx;
			background: linear-gradient( 90deg, #C8F673 0%, #98F083 100%);
			border-radius: 44rpx;
			margin: 0 auto;
			margin-top: 40rpx;
		}
		.my-content {
			padding: 30rpx;
			color: #fff;

			.info-box {
				padding: 30rpx;
				background: linear-gradient(134deg, rgba(255, 227, 211, 0.06) 0%, rgba(67, 130, 84, 0.26) 100%);
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				border: 4rpx solid rgba(108, 233, 137, 0.12);
				position: relative;

				.up-tips {
					position: absolute;
					top: 0;
					right: 0;
					padding: 10rpx 30rpx;
					background: linear-gradient(134deg, rgba(200, 246, 115, 0.06) 0%, rgba(200, 246, 115, 0.26) 100%);
					border-radius: 6rpx 32rpx 6rpx 32rpx;
					border: 4rpx solid rgba(108, 233, 137, 0.12);
					color: #A1FFA9;
					font-size: 28rpx;
				}

				.info-head {
					display: flex;
					align-items: center;
					font-weight: 600;
					font-size: 28rpx;

					image {
						width: 70rpx;
						height: 70rpx;
						margin-right: 20rpx;
						border-radius: 50%;
					}
				}

				.info-num {
					padding: 20rpx 0;
					display: flex;
					justify-content: space-between;
					text-align: center;
					margin-top: 8rpx;

					.num-item {
						width: 33%;

						.num {
							font-size: 24rpx;
							color: #A1FFA9;

							text {
								font-weight: 600;
								font-size: 36rpx;
							}
						}

						.num-text {
							color: #eee;
							font-size: 24rpx;
							margin-top: 10rpx;
						}
					}
				}

				.order {
					height: 71rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-top: 32rpx;
					font-size: 24rpx;
					color: #dcdcdc;
					background-image: url('../../../static/community/text-bg.png');
					background-repeat: no-repeat;
					background-size: 100% 71rpx;
					padding: 0 20rpx;
					.order-time {
						color: #fff;
					}
				}
			}

			.head {
				display: flex;
				padding: 30rpx 0;

				.head-item {
					width: 160rpx;
					height: 66rpx;
					font-size: 24rpx;
					margin-right: 30rpx;
					border-radius: 50rpx;
					color: #17191A;
					display: flex;
					align-items: center;
					justify-content: center;

					image {
						width: 28rpx;
						height: 28rpx;
						margin-right: 10rpx;
					}
				}

				.activity {
					background: linear-gradient( 90deg, #C8F673 0%, #98F083 100%);
					border: 4rpx solid rgba(108, 233, 137, 0.1)
				}

				.stillness {
					color: #A1FFA9;
					background-color: rgba(255, 255, 255, .05);
				}
			}

			.payment {
				background: linear-gradient(134deg, rgba(255, 227, 211, 0.06) 0%, rgba(67, 130, 84, 0.26) 100%);
				border: 4rpx solid rgba(108, 233, 137, 0.12);
				padding: 30rpx;
				border-radius: 30rpx;
				margin-bottom: 30rpx;

				.payment-item {
					display: flex;
					justify-content: space-between;
					align-items: center;
					padding-bottom: 30rpx;
					border-bottom: 1rpx solid rgba(255, 255, 255, .2);
					margin-top: 30rpx;

					.payment-title {
						color: #ddd;
					}

					.payment-right {
						display: flex;
						align-items: center;
						color: #fff;
						font-size: 28rpx;
						
						.cory{
							margin-left: 20rpx;
							color: #A1FFA9;
						}
					}

					.code {
						width: 390rpx;
						margin: 0 auto;
						padding: 10rpx;
					}
				}

				.payment-item:first-child {
					margin: 0;
				}

				.payment-item:last-child {
					border: none;
					padding: 0;
				}
			}

			.up-box {
				padding: 30rpx;
				background: linear-gradient( 134deg, rgba(255,227,211,0.06) 0%, rgba(67,130,84,0.26) 100%);
				border: 4rpx solid rgba(108,233,137,0.12);
				border-radius: 30rpx;
				margin: 30rpx 0;
				display: flex;
				justify-content: center;
				.codeadd{
					width: 390rpx;
					height: 625rpx;
					position: relative;
					
					.icon {
						width: 28px;
						position: absolute;
						top: 45%;
						left: 0;
						right: 0;
						margin: 0 auto;
					}
				}
				.code {
					width: 390rpx;
					padding: 10rpx;
					margin: 0 auto;
				}
			}
		}
	}
</style>